home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 December / PCWDEC06.iso / Software / Freeware / Gmail Manager 0.5.1 / gmanager051.xpi / components / gmPrefs.js < prev    next >
Encoding:
Text File  |  2006-08-28  |  2.8 KB  |  114 lines

  1. // Gmail Manager
  2. // By Todd Long <longfocus@gmail.com>
  3. // http://www.longfocus.com/firefox/gmanager/
  4.  
  5. const GM_CC = Components.classes;
  6. const GM_CI = Components.interfaces;
  7.  
  8. function gmPrefs() {}
  9. gmPrefs.prototype = {
  10.   _node: null,
  11.   _temp: null,
  12.   _nodeList: null,
  13.   _prefs: null,
  14.   
  15.   get node() { return this._node; },
  16.   get temp() { return this._temp; },
  17.   get nodeList() { return this._nodeList; },
  18.   
  19.   set node(aNode)
  20.   {
  21.     this._node = aNode;
  22.     this._temp = this._node.cloneNode(true);
  23.     this._nodeList = this._temp.getElementsByTagName("pref");
  24.     this._prefs = new Array();
  25.     
  26.     for (var i = 0; i < this._nodeList.length; i++)
  27.     {
  28.       var pref = new Object();
  29.       var item = this._nodeList.item(i);
  30.       
  31.       pref.id = item.getAttribute("id");
  32.       pref.type = item.getAttribute("type");
  33.       pref.value = item.getAttribute("value");
  34.       
  35.       this._prefs[pref.id] = pref;
  36.     }
  37.   },
  38.   
  39.   load: function()
  40.   {
  41.     this._temp = this._node.cloneNode(true);
  42.     this._nodeList = this._temp.getElementsByTagName("pref");
  43.   },
  44.   
  45.   save: function()
  46.   {
  47.     this.node = this._temp;
  48.   },
  49.   
  50.   getValue: function(aId)
  51.   {
  52.     return this._prefs[aId].value;
  53.   },
  54.   
  55.   getBoolValue: function(aId)
  56.   {
  57.     return (this.getValue(aId) == "true" ? true : false);
  58.   },
  59.   
  60.   getIntValue: function(aId)
  61.   {
  62.     return parseInt(this.getValue(aId));
  63.   },
  64.   
  65.   QueryInterface: function(iid)
  66.   {
  67.     if (!iid.equals(GM_CI.gmIPrefs) && 
  68.         !iid.equals(GM_CI.nsISupports))
  69.       throw Components.results.NS_ERROR_NO_INTERFACE;
  70.     return this;
  71.   }
  72. }
  73.  
  74. var myModule = {
  75.   firstTime: true,
  76.   
  77.   myCID: Components.ID("{b1830600-015a-11db-92e3-0800200c9a66}"),
  78.   myDesc: "Service for preferences",
  79.   myProgID: "@longfocus.com/gmanager/prefs;1",
  80.   myFactory: {
  81.     createInstance: function (outer, iid) {
  82.       if (outer != null)
  83.         throw Components.results.NS_ERROR_NO_AGGREGATION;
  84.       
  85.       return (new gmPrefs()).QueryInterface(iid);
  86.     }
  87.   },
  88.  
  89.   registerSelf: function (compMgr, fileSpec, location, type)
  90.   {
  91.     if (this.firstTime) {
  92.       this.firstTime = false;
  93.       throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
  94.     }
  95.     
  96.     compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  97.     compMgr.registerFactoryLocation(this.myCID, this.myDesc, this.myProgID, fileSpec, location, type);
  98.   },
  99.  
  100.   getClassObject: function (compMgr, cid, iid)
  101.   {
  102.     if (!cid.equals(this.myCID))
  103.       throw Components.results.NS_ERROR_NO_INTERFACE;
  104.     
  105.     if (!iid.equals(Components.interfaces.nsIFactory))
  106.       throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  107.     
  108.     return this.myFactory;
  109.   },
  110.   
  111.   canUnload: function(compMgr) { return true; }
  112. };
  113.  
  114. function NSGetModule(compMgr, fileSpec) { return myModule; }